package com.lingyistudio.common.util;

import lombok.extern.slf4j.Slf4j;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @ClassName: TimeModel
 * @Description:
 * @Author: cheng
 * @Date: 2019/5/24
 */
@Slf4j
public class TimeModel {
    private static TimeModel timeModel = null;
    public  int year; //年份
    public  int month; //月份
    public  int day; //几号
    public  int hour; //小时
    public  int minute; //分
    public  int second; //秒

    private TimeModel() {
    }

    public static TimeModel getTimeModel() {
        if (timeModel == null) {
            synchronized (TimeModel.class) {
                if (timeModel == null) {
                    timeModel = new TimeModel();
                    timeModel.setTime();
                    return timeModel;
                }
            }
        }
        return timeModel;
    }

    public void setTime() {
        Date nowTime = new Date(System.currentTimeMillis());
        SimpleDateFormat sdfYear = new SimpleDateFormat("yyyy"); //四位年份
        SimpleDateFormat sdMonth = new SimpleDateFormat("MM");
        SimpleDateFormat sdDay = new SimpleDateFormat("dd");
        SimpleDateFormat sdHour = new SimpleDateFormat("HH");
        SimpleDateFormat sdMinute = new SimpleDateFormat("mm");
        SimpleDateFormat sdSecond = new SimpleDateFormat("ss");
        year = Integer.parseInt(sdfYear.format(nowTime));
        month = Integer.parseInt(sdMonth.format(nowTime));
        day = Integer.parseInt(sdDay.format(nowTime));
        hour = Integer.parseInt(sdHour.format(nowTime));
        minute = Integer.parseInt(sdMinute.format(nowTime));
        second = Integer.parseInt(sdSecond.format(nowTime));
    }
}
